<!--
 * @Author: yaojian66 1327629137@qq.com
 * @Date: 2022-07-05 14:27:23
 * @LastEditors: yaojian66 1327629137@qq.com
 * @LastEditTime: 2022-07-05 14:27:43
 * @FilePath: \geyao\第一百零八题 接口.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>接口</title>
</head>

<body>
  <script type="text/javascript">
    let data = [{
        name: 'nowcoder1'
      },
      {
        name: 'nowcoder2'
      }
    ]

    const _api = string => {
      // 补全代码
      // 补全代码
      if (string.indexOf('get?') != -1) {
        return data
      } else if (string.indexOf('update?') != -1) {
        var index1 = string.indexOf('=')
        var index2 = string.indexOf('&')
        // 从索引1的下一个位置开始查找
        var index3 = string.indexOf('=', index1 + 1)
        var index4 = string.length
        var old = string.slice(index1 + 1, index2)
        var newV = string.slice(index3 + 1, index4)
        data.forEach((item) => {
          if (item.name === old) {
            item.name = newV
          }
        })

      } else {
        return ''
      }
    }
  </script>
</body>

</html>